import annocation.BtnListen;
import process.ProcessEvent;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author:谢君臣
 * @Date:2021/8/11-20:19
 * @version:1.0
 * @function:
 */
public class Main {
    private JFrame jFrame = new JFrame("测试注解事件");
    @BtnListen(OkListener.class)
    private JButton okBtn = new JButton("确定");
    @BtnListen(CancelListener.class)
    private JButton cancelBtn = new JButton("取消");

    public void init() throws InstantiationException, IllegalAccessException {
        JPanel jPanel = new JPanel();
        jPanel.add(okBtn);
        jPanel.add(cancelBtn);
        jFrame.add(jPanel);
        jFrame.pack();
        jFrame.setLocation(300,300);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        ProcessEvent.process(this);
    }
    public static void main(String[] args) {
        try {
            new Main().init();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static class OkListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            System.out.println("确定");
        }
    }
    public static class CancelListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            System.out.println("取消");
        }
    }
}
